/**
 * Project Name:fire-industry-DM-center
 * File Name:MybatisPlusConfig.java
 * Package Name:com.firestone.config.plus
 * Date:2018年3月26日下午3:05:36
 *
*/

package com.firestone.config.plus;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.baomidou.mybatisplus.entity.GlobalConfiguration;
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import com.firestone.core.utils.BlankUtil;

/**
 * @Description: TODO(mybatis-plus插件配置)
 * @author CAIYJ
 * @date 2018年3月26日 下午3:05:36
 */
@Configuration
public class MybatisPlusConfig {
    
    private static final Logger logger = LogManager.getLogger(MybatisPlusConfig.class);
    
//  mybatisPlus全局配置
  @Bean(name = "basisGlobalConfig")
  public GlobalConfiguration globalConfig(
          @Value("${mybatisPlus.globalConfig.idType}") Integer idType, //主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
          @Value("${mybatisPlus.globalConfig.dbColumnUnderline}") Boolean dbColumnUnderline, //驼峰下划线转换
          @Value("${mybatisPlus.globalConfig.isCapitalMode}") Boolean isCapitalMode //数据库大写下划线转换
  ) {
      logger.info("初始化GlobalConfiguration");
      GlobalConfiguration globalConfig = new GlobalConfiguration();
      // 主键类型
      if ( !BlankUtil.isBlank(idType)) {
          globalConfig.setIdType(idType);
      }
      // 驼峰下划线转换
      if ( !BlankUtil.isBlank(dbColumnUnderline)) {
          globalConfig.setDbColumnUnderline(dbColumnUnderline);
      }
      // 数据库大写下划线转换
      if ( !BlankUtil.isBlank(isCapitalMode)) {
          globalConfig.setCapitalMode(isCapitalMode);
      }
      return globalConfig;
  }
    
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor().setDialectType("mysql");
    }
}
